package ljl.codetop300;

import java.util.Random;

public class _384_shuffle_arr {

  /**
   * 这不是我最擅长的打乱数组吗
   */
  class Solution {

    int[] nums;
    Random r = new Random();
    public Solution(int[] nums) {
      this.nums = nums;
    }

    public int[] reset() {
      return nums;
    }

    public int[] shuffle() {
      int[] res = nums.clone();
      for (int i = res.length - 1; i > 0; i--) {
        int j = r.nextInt(i + 1);
        if (i == j) continue;
        int t = res[i];
        res[i] = res[j];
        res[j] = t;
      }
      return res;
    }
  }
}
